
//获得课程上传视频的总量
function zhu3(){
    $.ajax({
        type:'post',
        url:'/homedata/getCourseVideo',
        data:{},
        dataType:'json',
        success:function (res){
            var q = document.getElementById("imgnum1")
            q.innerText = res;
        }
    })
}
//查询所有用户
function zhu6(){
    $.ajax({
        type:'post',
        url:'/homedata/getNumberOfAllUsers',
        data:{},
        dataType:'json',
        success:function (res){
            var qqqq = document.getElementById("bxtext7")
            qqqq.innerText = res;
        }
    })
}


//查询今日注册的用户
function zhu7(){
    $.ajax({
        type:'post',
        url:'/homedata/getCurrentDayUser',
        data:{},
        dataType:'json',
        success:function (res){
            var qqqqq = document.getElementById("bxtext1")
            qqqqq.innerText = res;
        }
    })
}

//查询昨日注册的用户
function zhu8(){
    $.ajax({
        type:'post',
        url:'/homedata/getYesterdayUser',
        data:{},
        dataType:'json',
        success:function (res){
            var qqqqqq = document.getElementById("bxtext3")
            qqqqqq.innerText = res;
        }
    })
}

//查询本月新增注册的用户
function zhu9(){
    $.ajax({
        type:'post',
        url:'/homedata/getUsersOfThisMonth',
        data:{},
        dataType:'json',
        success:function (res){
            var qqqqqqq = document.getElementById("bxtext5")
            qqqqqqq.innerText = res;
        }
    })
}


//查询课程视频点赞总量
function zhu5(){
    $.ajax({
        type:'post',
        url:'/homedata/getCurrculumCollectionQuantity',
        data:{},
        dataType:'json',
        success:function (res){
            var qqq = document.getElementById("imgnum3")
            qqq.innerText = res;
        }
    })
}
//查询课程视频点赞总量
function zhu4(){
    $.ajax({
        type:'post',
        url:'/homedata/getTotalNumberOfVideoLikes',
        data:{},
        dataType:'json',
        success:function (res){
            var qq = document.getElementById("imgnum4")
            qq.innerText = res;
        }
    })
}
//获得已上架的商品数量
function zhu(){
    $.ajax({
        type:'post',
        url:'/homedata/getCommodityQuantity',
        data:{},
        dataType:'json',
        success:function (res){
            var p = document.getElementById("btext3")
            p.innerText = res;
        }
    })
}
//获得已上架的课程数量
function zhu2(){
    $.ajax({
        type:'post',
        url:'/homedata/getConstantQuantity',
        data:{},
        dataType:'json',
        success:function (res){
            var pp = document.getElementById("btext1")
            pp.innerText = res;
        }
    })
}



$.ajax({
    type:'post',
    url:'/getCouponCount',
    data:{},
    dataType:'json',
    success:function (res){
        sessionStorage.setItem("couponArray", JSON.stringify(res.data));
    }
})

var xAxisArray = new Array();
var fJsArray = new Array();
var jsArray = new Array();
var ftArray = new Array();
var jfArray = new Array();
$.ajax({
    type:'post',
    url:'/YltUser/InfoManage/getInfoDataByInsider',
    data:{
        insider:1
    },
    dataType:'json',
    success:function (res){
        res.data.forEach(function (i){
            xAxisArray.push(i.clickDate)
            fJsArray.push(i.count)
        })
        sessionStorage.setItem("xAxisArray", JSON.stringify(xAxisArray));
        sessionStorage.setItem("fJsArray", JSON.stringify(fJsArray));
    }
})
$.ajax({
    type:'post',
    url:'/YltUser/InfoManage/getInfoDataByInsider',
    data:{
        insider:2
    },
    dataType:'json',
    success:function (res){
        res.data.forEach(function (i){
            jsArray.push(i.count)
        })
        sessionStorage.setItem("jsArray", JSON.stringify(jsArray));
    }
})
$.ajax({
    type:'post',
    url:'/YltUser/InfoManage/getInfoDataUserSeal',
    data:{
        sealState:0
    },
    dataType:'json',
    success:function (res){
        res.data.forEach(function (i){
            ftArray.push(i.count)
        })
        sessionStorage.setItem("ftArray", JSON.stringify(ftArray));
    }
})
$.ajax({
    type:'post',
    url:'/YltUser/InfoManage/getInfoDataUserSeal',
    data:{
        sealState:1
    },
    dataType:'json',
    success:function (res){
        res.data.forEach(function (i){
            jfArray.push(i.count)
        })
        sessionStorage.setItem("jfArray", JSON.stringify(jfArray));
    }
})

window.onload = function (){
    a();
    zhu();
    zhu2();
    zhu3();
    zhu4();
    zhu5();
    zhu6();
    zhu7();
    zhu8();
    zhu9();
}
//刷新页面
$('#refresh').click(function (){
    location.reload();
});


layui.use(['layer', 'miniTab','echarts'],function (){

    var $ = layui.jquery,
        layer = layui.layer,
        miniTab = layui.miniTab,
        echarts = layui.echarts;

    miniTab.listen();

})

//
// $("#bodyimg1").on('click',function (){
//
//     // window.location.href="http://localhost:3030/carousel/updatecarousel.html";
//     console.log("123")
//
//     let attr = $(this).find('div').attr("data-menuid");
//     let attr1 = $(this).find('div').attr("data-title");
//     let attr0 = $(this).find('div').attr("data-src");
//     var menuDd = $(".layui-tab-title li[lay-id]",parent.document);
//     var isData = false;
//     $.each(menuDd,function (){
//
//         let attr2 = $(this).attr("lay-id");
//         if (attr == attr2){
//             isData = true;
//         }
//
//
//
//     })
//
//     // if (isData == false){
//     //         parent.retiao(attr,attr0,attr1)
//     // }else {
//     //     parent.retiaoone(attr);
//     // }
//
//
//
//
//
// })










//柱状图，折线图，饼状图渲染
// 获取box元素
var box = document.getElementsByClassName("box")[0];
// 获取btnShowBar元素
var btnShowBar = document.getElementsByClassName("btnShowBar")[0];

var btnShowLine = document.getElementsByClassName("btnShowLine")[0];
// var btnShowPie = document.getElementsByClassName("btnShowPie")[0];
// 定义按钮单击事件
function a(){
    $.get('/browse/getAll', function (data) {

        liuliang_list = [];
        date_list = [];
        name_list = [];
        // 将json数据写入数组
        for (var i = 0; i < data.length; i++) {
            name_list.push(data[i].name);
            date_list.push(data[i].date);
            liuliang_list.push(data[i].liuliang);
        }

        // 1. 初始化ECharts
        var my_box = echarts.init(box);

        // 2. 进行参数配置
        var option = {
            // 标题
            tooltip:{}, //鼠标停在图标之后的显示
            title: {
                text: "登陆流量",
                x: "center",
                y: "top",
                textAlign: "left",
                textStyle: {
                    fontFamily: "楷体",
                    fontSize: 35,
                    textStyle: "bold"
                }
            },
            // 图例
            legend: {
                left: "right",
                orient: "vertical"
            },
            // x轴数据
            xAxis: {
                data: name_list
            },
            // y轴数据
            yAxis: {},
            // 数据信息
            series: [
                {
                    name: "流量",
                    type: "bar",
                    color:"#c23531",
                    data: liuliang_list,

                    itemStyle: {
                        normal: {
                            color: function(params) {
                                //注意，如果颜色太少的话，后面颜色不会自动循环，最好多定义几个颜色
                                var colorList = ['#c23531','#c23531', '#c23531', '#c23531'];
                                return colorList[params.dataIndex]
                            }
                        }
                    }
                }
            ]
        }

        // 3. 可视化呈现
        my_box.setOption(option);
    });
}
//单击柱状图渲染
btnShowBar.onclick = function () {
    // 获取后台返回的JSON数据
    a();
}

//单击折线图渲染
btnShowLine.onclick = function () {
    // 获取后台返回的JSON数据
    $.get('/browse/getAll', function (data) {
        liuliang_list = [];
        date_list = [];
        name_list = [];
        // 将json数据写入数组
        for (var i = 0; i < data.length; i++) {
            name_list.push(data[i].name);
            date_list.push(data[i].date);
            liuliang_list.push(data[i].liuliang);
        }

        // 1. 初始化ECharts
        var my_box = echarts.init(box);
        // 2. 进行参数配置
        var option = {
            // 标题
            title: {
                text: "登陆流量折线图",
                x: "center",
                y: "top",
                textAlign: "left",
                textStyle: {
                    fontFamily: "楷体",
                    fontSize: 35,
                    textStyle: "bold"
                }
            },
            // 图例
            legend: {
                left: "right",
                orient: "vertical"
            },
            // x轴数据
            xAxis: {
                data: name_list
            },
            // y轴数据
            yAxis: {},
            // 数据信息
            series: [
                {
                    name: "流量",
                    type: "line",
                    data: liuliang_list,
                    itemStyle: {
                        normal: {
                            color: '#0000aa'
                        }
                    }
                }
            ]
        }
        // 3. 可视化呈现
        my_box.setOption(option);
    });
}


